package com.shengsheng.expschedule.service.expschedule.controller.admin;


import com.shengsheng.expschedule.base.result.R;
import com.shengsheng.expschedule.service.expschedule.entity.Class;
import com.shengsheng.expschedule.service.expschedule.service.ClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 班级表 前端控制器
 * </p>
 *
 * @author yuan
 * @since 2021-09-29
 */
@RestController
@RequestMapping("/admin/expschedule/class")
@Api(tags = "班级管理")
@RefreshScope
public class ClassController {

    @Autowired
    private ClassService classService;

    @ApiOperation("添加班级")
    @PostMapping("/saveClass")
    public R saveClass(@ApiParam(value = "班级对象",required = true)
                       @RequestBody Class c) {
        Class aClass = classService.saveClass(c);
        if (aClass != null) return R.ok().data("class",aClass).message("添加成功");
        return R.error().message("添加失败");
    }

    @ApiOperation("删除班级")
    @DeleteMapping("/remove/{id}")
    public R removeClassById(@ApiParam(value = "删除班级 Id")
                             @PathVariable String id) {
        if (classService.removeClassById(id)) return R.ok().message("删除成功");
        return R.error().message("删除失败");
    }

    @ApiOperation("查询所有班级")
    @GetMapping("/getClassList")
    public R getClassList() {

        return R.ok()
                .data("items", classService.getClassList())
                .message("获取成功");
    }
}

